<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Title</title>
    
    <style>
      .box {
        border: 1px gray solid;
        border-radius: 10px;
        padding: 15px;
      }
      
      .title {
        font-size: 15px;
        font-weight: bold;
        margin: 10px;
      }
      
      .card {
        display: flex;
        column-gap: 10px;
      }
      
      .card-son {
        width: 200px;
        height: 50px;
        padding: 10px;
        margin: 10px;
        display: flex;
        justify-content: center;
        align-items: center;
        color: darkgray;
        background: pink;
      }
    </style>
  </head>
  
  <body>
    <div id="app">
      <!-- Array中改变原数组的API -->
      <div class="box">
        <div class="title">Array中改变原数组的API
          <button @click="changeArr()">删除元素</button>
        </div>
        <div class="card">
          <div v-for="(item,index) in itemsArr1" class="card-son">{{index}}</div>
        </div>
      </div>
      <br>
      
      <!-- Array中不改变原数组的API -->
      <div class="box">
        <div class="title">Array中不改变原数组的API
          <button @click="noChangeArr()">删除元素</button>
        </div>
        <div class="card">
          <div v-for="(item,index) in itemsArr2" class="card-son">{{index}}</div>
        </div>
      </div>
      <br>
      
      <!-- 需求：不改变原数组但希望页面更新 -->
      <div class="box">
        <div class="title">需求：不改变原数组但希望页面更新</div>
        <div class="card">
          <div v-for="(item,index) in noChangeArrButUpdate" class="card-son">{{index}}</div>
        </div>
      </div>
    </div>
  </body>
  
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  
  <script>
    Vue.createApp({
      data() {
        return {
          itemsArr1: [
            {
              label: '一',
              value: 'One'
            },
            {
              label: '二',
              value: 'Two'
            },
            {
              label: '三',
              value: 'Three'
            },
            {
              label: '四',
              value: 'Four'
            },
            {
              label: '五',
              value: 'Five'
            },
            {
              label: '六',
              value: 'Six'
            },
          ],
          itemsArr2: [
            {
              label: '一',
              value: 'One'
            },
            {
              label: '二',
              value: 'Two'
            },
            {
              label: '三',
              value: 'Three'
            },
            {
              label: '四',
              value: 'Four'
            },
            {
              label: '五',
              value: 'Five'
            },
            {
              label: '六',
              value: 'Six'
            },
          ],
        };
      },
      methods: {
        changeArr() {
          const firstArr = this.itemsArr1;
          console.log('原数组', firstArr);
          
          this.itemsArr1.shift();
          const secondArr = this.itemsArr1;
          console.log('变数组', secondArr);
        },
        noChangeArr() {
          const firstArr = this.itemsArr2;
          console.log('原数组', firstArr);
          
          this.itemsArr2.slice(0, 2);
          const secondArr = this.itemsArr2;
          console.log('变数组', secondArr);
        }
      },
      computed: {
        noChangeArrButUpdate() {
          const firstArr = this.itemsArr2;
          console.log('原数组', firstArr);
          
          const array = this.itemsArr2.filter((item, index) => {
            return index !== 0;
          });
          const secondArr = this.itemsArr2;
          console.log('变数组', secondArr);
          
          return array;
        }
      }
    }).mount('#app');
  </script>
</html>